Triggers

Hi,

Is it possible to create a trigger for all modules in a folder?
DXLUser - Mon Aug 08 15:56:52 EDT 2011

Re: Triggers
llandale - Mon Aug 08 18:16:30 EDT 2011

No.

Triggers are stored in a Module, a Project, or the Database. In this case you will want to deploy the trigger in the folder's parent Project, but the trigger code itself checks the folder and if its not the right one, just stops. So if its a module level trigger then you can get the module name and make sure its prefix is the name of the project combined with the name of the folder.

NameFolder = "MyTriggerFolder"
NamePath = "/" name(current Project "/" NameFolder
NameMod = name(module(current Trigger))
if (length(NameMod) > length(NamePath) and
NameMod0:length(NamePath)-1 == NamePath) //
then Trigger applies to this module
else Trigger does not apply. Do nothing.
....
trigger(NameTrigger, project->module->formal, post, open 6, DXLCode)

  • Louie

Well, actually "Almost".

Select the folder in the right pane and use the File menu to convert it to a project. Open it up and deploy your trigger. Go back with it in the right pane and convert it back to a folder. Seems to be working sometimes. DISCLAIMER: the hackles on the back of my neck are up; that goodness I'm getting sporadic Exception Violations forcing the abandonment of this violation of the laws of the universe.

Not checking it out closely but I suspect the Trigger is already loaded on the Client but there are hiccups using a Trigger for a Project that no longer exists.

It seems at one point the Trigger was sucessfully moved up into the higher Project.

Re: Triggers
OurGuest - Tue Aug 09 09:12:45 EDT 2011

The help file says: Specific module triggers, including all object level and attribute level triggers, are stored in the module to which they apply. If the trigger specification does not name a specific module, they are stored in the current module.

Thus you would have to open each module and store the module level trigger in each module in the folder.

Re: Triggers
llandale - Tue Aug 09 15:18:08 EDT 2011

OurGuest - Tue Aug 09 09:12:45 EDT 2011
The help file says: Specific module triggers, including all object level and attribute level triggers, are stored in the module to which they apply. If the trigger specification does not name a specific module, they are stored in the current module.

Thus you would have to open each module and store the module level trigger in each module in the folder.

This is not the first time the manual is wrong. They recently upgraded the Trigger help section and now its "bad" instead of "abysmal".

This code inserts an attribute level trigger in the project. It detects any change to Object Text in any module in the Project, and infoBox's that fact.

string DXLCode =
"    set(trigPreConPass)
        Trigger trg = current;    if (null trg) halt()  // Error?
        AttrDef ad  = attrdef(trg); if (null ad)        halt()  // Error?
        string      Name = ad.name
        if (Name == \"Object Text\") infoBox(\"Text change detected in Trigger\")
"  // end string DXLCode
 
string NameTrig = "DetectTextChange"
Trigger trg
for trg in (current Project) do
{  if (name(trg) == NameTrig  and
       confirm("Delete trig '" NameTrig "'??"))
   {  delete(trg)
      halt   // or break
   }
}
if (confirm("Create trigger '" NameTrig "' in project??"))
{  trigger(NameTrig, project->module->all->attribute,
                pre, save, 5, DXLCode)
}


Looking at the "level" string project->module->all->attribute...
o "project->" means put in the current Project. "project->all->" means store in the database.
o "module->all" means it applies to all modules (in the project). "module->" would mean the current Module, but that doesn't make sense in this case since we are putting it in the current Project.
o "attribute" means its an attribute trigger.

Trigger level assembly is confusing and I'm sure I've never got it right the first time; including this time.

 

 

  • Louie